<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //instanceof 判断某个实例和构造器在原型链上是否有关系
        //ES5 精确判断数据类型
        // var arr = [];
        // var obj = {}
        // var reg =/a/;
        // // 就这句 ---> Object.prototype.toString.call(arr).slice(8,-1)
        // console.log(Object.prototype.toString.call(arr).slice(8,-1))
        // console.log(Object.prototype.toString.call(obj).slice(8,-1))
        // console.log(Object.prototype.toString.call(reg).slice(8,-1))

        //2.深拷贝,数组/对象拷贝
        function deepCopy(obj1){
            var obj2 = Object.prototype.toString.call(obj1).slice(8,-1) === 'Array'?[]:{};
            for(var key in obj1){
                obj2[key] = obj1[key]
            }
            return obj2;
        }
        var arr =['1','2','3']
        var newArr = deepCopy(arr);
        console.log(newArr);

        //3.深拷贝的多层问题
        obj1 = {name : ':·.',hobby : {game:'盐与牺牲'}}
        obj2 = deepCopy(obj1)

        obj2.name = '腐腐'
        console.log(obj1.name);//第一层的不会改
        obj2.hobby.game = '盐与避难所'
        console.log(obj1.hobby);//第二层就会跟着变
        


    </script>
</body>
</html>